import Vue from 'vue'
import Vuerouter from 'vue-router'

const originpush = Vuerouter.prototype.push    //漏油点击报错
Vuerouter.prototype.push = function push(location) {
    return originpush.call(this, location).catch(err => err)
}

Vue.use(Vuerouter)

const home = () => import('@/views/home/home')
const login = () => import('@/views/login/login')
const charts = () => import('@/components/charts')
const wode = () => import('@/views/wode/wode')
const wodet = () => import('@/views/wode/wodet')
const shopping = () => import('@/views/shopping')

export const routers = [
    {
        path: '/',
        component: home,
        meta: {
            name: '主页',
            icon: 'el-icon-menu'
        },
        children: [
            {
                path: '',
                component: charts,
            }
        ]
    },
    {
        path: '/user',
        component: home,
        meta: {
            name: '我的',
            icon: 'el-icon-s-custom'
        },
        children: [
            {                        // 分页导航时候 切换的到路由时会到第一个儿子
                path: '',
                redirect: '/wode'   //重定向
            },
            {
                path: '/wode',
                component: wode,
                meta: {
                    name: '用户管理',
                    icon: 'el-icon-orange'
                }
            },
            {
                path: '/wodet',
                component: wodet,
                meta: {
                    name: '用户信息',
                    icon: 'el-icon-chat-dot-square'
                },
            }
        ]
    },
    {
        path: '/shopping',
        component: home,
        meta: {
            name: '品牌管理',
            icon: 'el-icon-s-goods'
        },
        children:
            [
                {
                    path: '',
                    component: shopping,
                }
            ]
    }
]
const routera = [
    {
        path: '/login',
        component: login
    }
]

const router = new Vuerouter({
    routes: routers.concat(routera),
    mode: 'history'
})
export default router